package ThreadPool.lagou.concurrent.interrupt.demo01;

import java.util.concurrent.TimeUnit;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description:TODO
 * @date 2022/10/11 20:56
 */
public class InterruptDemo03 {

    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            for (;;){
                if(Thread.currentThread().isInterrupted()){
                    System.out.println(Thread.currentThread().getName()
                            +"\t 中断标志位："+Thread.currentThread().isInterrupted()+"");
                    break;
                }
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("hello InterruptDemo03...");
            }
        },"t1");
        t1.start();
        // 暂停1秒钟
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        new Thread(()->{
            t1.interrupt();
        },"t2").start();

    }
}
